import { defineStore } from 'pinia'
import { store } from '/@/store'
import type { AxiosResponse } from 'axios'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'
import type { DataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'

import expressionService from '/@/api/cn/core/kpis/expressionService'

import type { Expression } from '/@/model/cn/core/kpis/eo/Expression'
import type { ExpressionQO } from '/@/model/cn/core/kpis/qo/ExpressionQO'
import type { ExpressionVO } from '/@/model/cn/core/kpis/vo/ExpressionVO'

interface ExpressionState {
}

export const useExpressionStore = defineStore({
  id: 'expression',
  state: (): ExpressionState => ({
  }),
  getters: {
  },
  actions: {
    save(param: Param<Expression>): Promise<Res<Expression>> {
      return new Promise<Res<Expression>>((resolve, reject) => {
        expressionService.save(param).then((res: AxiosResponse<Res<Expression>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    saveBatch(param: Param<Expression>): Promise<Res<Expression>> {
      return new Promise<Res<Expression>>((resolve, reject) => {
        expressionService.saveBatch(param).then((res: AxiosResponse<Res<Expression>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    update(param: Param<Expression>): Promise<Res<Expression>> {
      return new Promise<Res<Expression>>((resolve, reject) => {
        expressionService.update(param).then((res: AxiosResponse<Res<Expression>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    updateBatch(param: Param<Expression>): Promise<Res<Expression>> {
      return new Promise<Res<Expression>>((resolve, reject) => {
        expressionService.updateBatch(param).then((res: AxiosResponse<Res<Expression>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    remove(param: Param<Expression>): Promise<Res<Expression>> {
      return new Promise<Res<Expression>>((resolve, reject) => {
        expressionService.remove(param).then((res: AxiosResponse<Res<Expression>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    removeBatch(param: Param<Expression>): Promise<Res<Expression>> {
      return new Promise<Res<Expression>>((resolve, reject) => {
        expressionService.removeBatch(param).then((res: AxiosResponse<Res<Expression>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    count(param: Param<ExpressionQO>): Promise<Res<Expression>> {
      return new Promise<Res<Expression>>((resolve, reject) => {
        expressionService.count(param).then((res: AxiosResponse<Res<Expression>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pk(param: Param<ExpressionQO>): Promise<Res<Expression>> {
      return new Promise<Res<Expression>>((resolve, reject) => {
        expressionService.pk(param).then((res: AxiosResponse<Res<Expression>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    query(param: Param<ExpressionQO>): Promise<Res<Expression>> {
      return new Promise<Res<Expression>>((resolve, reject) => {
        expressionService.query(param).then((res: AxiosResponse<Res<Expression>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    paging(param: Param<ExpressionQO>): Promise<Res<Expression>> {
      return new Promise<Res<Expression>>((resolve, reject) => {
        expressionService.paging(param).then((res: AxiosResponse<Res<Expression>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    countVo(param: Param<ExpressionQO>): Promise<Res<ExpressionVO>> {
      return new Promise<Res<ExpressionVO>>((resolve, reject) => {
        expressionService.countVo(param).then((res: AxiosResponse<Res<ExpressionVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pkVo(param: Param<ExpressionQO>): Promise<Res<ExpressionVO>> {
      return new Promise<Res<ExpressionVO>>((resolve, reject) => {
        expressionService.pkVo(param).then((res: AxiosResponse<Res<ExpressionVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    queryVo(param: Param<ExpressionQO>): Promise<Res<ExpressionVO>> {
      return new Promise<Res<ExpressionVO>>((resolve, reject) => {
        expressionService.queryVo(param).then((res: AxiosResponse<Res<ExpressionVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pagingVo(param: Param<ExpressionQO>): Promise<Res<ExpressionVO>> {
      return new Promise<Res<ExpressionVO>>((resolve, reject) => {
        expressionService.pagingVo(param).then((res: AxiosResponse<Res<ExpressionVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    dataImport(param: Param<string>): Promise<Res<Expression>> {
      return new Promise<Res<Expression>>((resolve, reject) => {
        expressionService.dataImport(param).then((res: AxiosResponse<Res<Expression>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    dataExport(param: Param<DataExportAO<ExpressionQO>>): Promise<Res<string>> {
      return new Promise<Res<string>>((resolve, reject) => {
        expressionService.dataExport(param).then((res: AxiosResponse<Res<string>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
  },
})

export function useExpressionStoreWithout() {
  return useExpressionStore(store)
}
